#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File    : heart_beat_service.py
@Author  : Spring
@Time    : 2024/12/11 10:52
@Desc    : 心跳相关业务类
"""
import jpype

from common.exception import HeartbeatError


# class HeartBeatServiceInitializer(type):
#     """
#     心跳元数据初始化类
#     """
#     def __init__(cls, name, bases, dct):
#         super().__init__(name, bases, dct)
#         Bootstrap.start()
#         cls.initialize()


class HeartBeatService:
    """
    心跳业务类
    """
    j_cls_heart_beat_manager = None

    @classmethod
    def initialize(cls):
        """
        初始化
        :return:
        """
        cls.j_cls_heart_beat_manager = jpype.JClass('com.venus.dms.heartbeat.HeartBeatManager')

    @classmethod
    def start_heart_beat(cls):
        """
        开启心跳
        :return:
        """
        try:
            cls.j_cls_heart_beat_manager.startHeartBeat()
        except Exception as e:
            raise HeartbeatError("开启心跳异常", e)

    @classmethod
    def stop_heart_beat(cls):
        """
        关闭心跳
        :return:
        """
        try:
            cls.j_cls_heart_beat_manager.stopHeartBeat()
        except Exception as e:
            raise HeartbeatError("关闭心跳异常", e)
